//
//  ShoppingDetailViewController.m
//  FunSport_WWL
//
//  Created by 王黎 on 16/4/29.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "ShoppingDetailViewController.h"

@interface ShoppingDetailViewController ()<UIWebViewDelegate>

@property (nonatomic,retain)UIWebView  *webView;



@end


@implementation ShoppingDetailViewController

#pragma mark --- 懒加载

- (UIWebView *)webView {
    
    if (!_webView) {
        
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
        
        //设置代理
        _webView.delegate = self;
        
    }
    
    return _webView;
    
}


#pragma mark - webViwe代理方法
//自适应高度
//去广告
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('display_in a_buttom')[0].style.display='none'"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('foot_joy')[0].style.display='none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('margin_content')[0].style.display = 'none'"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('margin_bottom')[0].style.display = 'none'"];
    
    [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:
                                                     @"var script = document.createElement('script');"
                                                     "script.type = 'text/javascript';"
                                                     "script.text = \"function ResizeImages() { "
                                                     "var myimg,oldwidth;"
                                                     "var maxwidth = %g;" // UIWebView中显示的宽度
                                                     "for(i=0;i <document.images.length;i++){"
                                                     "myimg = document.images[i];"
                                                     "if(myimg.width > maxwidth){"
                                                     "oldwidth = myimg.width;"
                                                     "myimg.width = maxwidth;"
                                                     "}"
                                                     "}"
                                                     "}\";"
                                                     "document.getElementsByTagName('head')[0].appendChild(script);",self.view.frame.size.width]];
    
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
    

}




- (void)viewDidLoad {
    
    [super viewDidLoad];
//
    
   // UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://media.thejoyrun.com/article/201604/%@.html",self.article_id]]];
    
    [self.webView loadRequest:request];
    
    [self.view addSubview:self.webView];
    
    
    
    
//    [self.view addSubview:self.tableView];
//
//    //注册xib
//    [self.tableView registerNib:[UINib nibWithNibName:@"ShoppingWebViewCell" bundle:nil] forCellReuseIdentifier:@"web_cell"];
//
//    //调用请求数据方法
//    [self fetchDatasourceWithUrl:kShoppingDetail parameter:self.parameter];
    
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
